import java.io.*;
import java.util.*;

/**
 * http://www.flownet.com/ron/papers/lisp-java
 * @author Moises Osorio
 */
public class JavaSolution {
	
	private static int MAX = 200;
	private static int[] ENCODING = new int[]{5, 7, 6, 3, 0, 4, 9, 9, 6, 1, 7, 8, 5, 1, 8, 8, 1, 2, 3, 4, 7, 6, 2, 2, 3, 9};
	
	private Node root;
	private char[] buffer;
	private PrintWriter out;
	
	public JavaSolution() {
		root = new Node();
		buffer = new char[MAX];
		out = new PrintWriter(new BufferedOutputStream(System.out));
	}
	
	/**
	 * Process the dictionary.
	 * @param in Dictionary
	 */
	public void processDictionary(InputStream in) {
		Scanner scan = new Scanner(in);
		while (scan.hasNextLine())
			addWordToDictionary(scan.nextLine());
	}
	
	/**
	 * Finds all the encodings of a list of phone numbers.
	 * @param in Phone numbers
	 */
	public void findEncodings(InputStream in) {
		Scanner scan = new Scanner(in);
		while (scan.hasNextLine())
			findEncodings(scan.nextLine());
		out.flush();
	}
	
	/**
	 * Adds a word to the dictionary, which is compressed in a trie (http://en.wikipedia.org/wiki/Trie).
	 * @param word Word to add.
	 */
	public void addWordToDictionary(String word) {
		Node current = root; // Root of the trie (suffix tree)
		for (int i = 0; i < word.length(); i++) {
			char ch = word.charAt(i);
			if (!Character.isLetter(ch)) // We skip non-letters
				continue;
			
			int n = ENCODING[Character.toLowerCase(ch) - 'a'];
			if (current.next[n] == null) // Select next branch
				current.next[n] = new Node();
			
			current = current.next[n];
		}
		
		current.matchings.add(word.toCharArray()); // Adds current matching to the end of the trie branch.
	}
	
	/**
	 * Finds the different encodings of the given phone number.
	 * @param phone The phone number to encode.
	 */
	public void findEncodings(String phone) {
		findEncodingsAt(0, phone.toCharArray(), 0, root, true);
	}
	
	private void findEncodingsAt(int position, char[] phone, int bufferPosition, Node node, boolean canBeDigit) {
		if (position == phone.length) {
			if (node != root) // Non-terminal node
				return;
			
			out.print(phone);
			out.print(": ");
			for (int i = 0; i < bufferPosition; i++)
				out.print(buffer[i]);
			out.println();
			
			return;
		}
		
		if (!Character.isDigit(phone[position])) { // Skip non-digits
			findEncodingsAt(position+1, phone, bufferPosition, node, canBeDigit);
			return;
		}
		
		int n = phone[position] - '0';
		
		if (node.next[n] != null) { // A word still matches
			findEncodingsAt(position+1, phone, bufferPosition, node.next[n], false);

			for (char[] match : node.next[n].matchings) {
				int bufPos = bufferPosition;
				if (bufPos > 0)
					buffer[bufPos++] = ' ';
				for (int i = 0; i < match.length; i++, bufPos++)
					buffer[bufPos] = match[i];
				
				findEncodingsAt(position+1, phone, bufPos, root, true); // Deep in the branch
			}
		}

		if (canBeDigit && !wordStarts(position, phone)) { // Can we put a digit?
			int bufPos = bufferPosition;
			if (bufPos > 0)
				buffer[bufPos++] = ' ';
			buffer[bufPos++] = phone[position];
			findEncodingsAt(position+1, phone, bufPos, node, false);
		}
	}
	
	/**
	 * Checks if a word starts from the given phone number position.
	 * @param position Position of the phone number.
	 * @param phone Phone number.
	 * @return If a word from the dictionary starts from the given position.
	 */
	private boolean wordStarts(int position, char[] phone) {
		Node node = root;
		for (; position < phone.length && node != null && node.matchings.isEmpty(); position++) {
			if (!Character.isDigit(phone[position]))
				continue;
			
			int n = phone[position] - '0';
			node = node.next[n];
		}
		
		return node != null && !node.matchings.isEmpty();
	}
	
	/**
	 * Trie node.
	 * @author Moises Osorio
	 */
	private class Node {
		private List<char[]> matchings;
		private Node[] next;
		
		public Node() {
			matchings = new ArrayList<char[]>();
			next = new Node[10];
		}
	}
	
	/**
	 * Entry point of the program.
	 * @param args dictionary.in phone-numbers.in
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {
		JavaSolution encoder = new JavaSolution();
		encoder.processDictionary(new FileInputStream(args[0]));
		encoder.findEncodings(new FileInputStream(args[1]));
	}
}
